package com.llcbenwu.social.qq.config;


import com.llcbenwu.configutils.SocialAutoConfigurerAdapter;
import com.llcbenwu.security.QQproperties;
import com.llcbenwu.social.ConnectionView;
import com.llcbenwu.social.qq.connect.QQConnectionFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.social.connect.ConnectionFactory;
import org.springframework.web.servlet.View;


/**
 * QQ的连接工厂
 * @author lilinchun
 * @date 2021/11/2 0002 11:36
 */
@Configuration
//ConditionalOnProperty作用：如果我配置了appId和appSecurity才生效如果没有配置就不生效
//@ConditionalOnProperty
public class QQAutoConfig extends SocialAutoConfigurerAdapter {


    @Override
    protected ConnectionFactory<?> createConnectionFactory() {
        QQproperties qQproperties=new QQproperties();
        return new QQConnectionFactory(qQproperties.getProviderId(),qQproperties.getAppId(),qQproperties.getAppSecret());
    }


    /***
     * connect/weixinConnected 绑定成功的视图
     * connect/weixinConnect 解绑的视图
     *
     * 两个视图可以写在一起，通过判断Model对象里有没有Connection对象来确定究竟是解绑还是绑定
     */
    @Bean({"connect/callback.doConnect", "connect/callback.doConnected"})
    //下面的注解的意思是当程序里有名字为weixinConnectedView的bean
    // 我写的默认的weixinConnectedView这个bean不会生效，也就是你可以写一个更好的bean来覆盖掉我的
    @ConditionalOnMissingBean(name = "weixinConnectedView")
    public View weixinConnectedView() {
        return new ConnectionView();
    }
}
